package ar.com.photo_admin.activity;

import com.nostra13.universalimageloader.core.ImageLoader;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import ar.com.photo_admin.R;
import ar.com.photo_admin.services.ServiceLayer;
import ar.com.photo_admin.services.ServiceLayerImpl.TokenOperationResponse;
import ar.com.photo_admin.services.Services;

public class ConfigurationActivity extends Activity {
	
	private ServiceLayer service;
	
	private ImageLoader imageLoader = ImageLoader.getInstance();
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.configuration);
		
		service = Services.createServiceLayer(this);
		
		final Button clearEvents = (Button) findViewById(R.id.clear_events);
		final Button clearImageCache = (Button) findViewById(R.id.clear_image_cache);
		
		clearEvents.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				TokenOperationResponse deleteAllTokens = service.deleteAllTokens();
				Toast.makeText(ConfigurationActivity.this, deleteAllTokens.message, Toast.LENGTH_SHORT).show();
			}
		});
		
		clearImageCache.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				String result = getString(R.string.clear_image_cache_success);
				
				try {
					imageLoader.clearMemoryCache();
					imageLoader.clearDiscCache();	
				} catch (Exception e) {
					result = getString(R.string.clear_image_cache_fail);
				}
				
				Toast.makeText(ConfigurationActivity.this, result, Toast.LENGTH_SHORT).show();
			}
		});
	}
}